﻿<%@ WebHandler Language="C#" Class="fabu" %>

using System;
using System.Web;
using System.Web.SessionState;
public class fabu : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {
        Visitor v = new Visitor();
        context.Response.ContentType = "text/plain";
        string name = context.Request["UserName"];
        string PhoneNum = context.Request["PhoneNum"];
        string Content = context.Request["Content"];
        string code = context.Session["code"].ToString().Trim();
        string htmlCode = context.Request["code"].Trim();
        string IPretrun = GetIPAddress();
        if (IPretrun.Trim() == null || IPretrun.Trim()=="")
        {
            IPretrun = "未知IP地址"; 
        }
        if (name != null && PhoneNum != null && Content != null && code != null && htmlCode == code)
        {
            if (v.AddLMessage(name, Content, PhoneNum, IPretrun))
            context.Response.Write(1);
            else
              context.Response.Write(0);
        }
        else
        {
            context.Response.Write(0);
        }

    }
    protected string GetIPAddress()
    {
       return IpSearch.GetAddressWithIP(getIp());
    }
    private static string getIp()
    {
        if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
            return System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];
        else
            return System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}